home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 431_01 / rdrive.c < prev    next >
C/C++ Source or Header  |  1994-10-07  |  2KB  |  101 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6.  
  7. #include "ifs.h"
  8. #include "rifs.h"
  9. #include "rclient.h"
  10. #include "local.h"
  11.  
  12. /*
  13.   RDRIVE /local=a /remote=b
  14.   RDRIVE /local=a
  15.   RDRIVE /remove
  16. */
  17. static char *options[]={ "/local=",
  18.                          "/remote=",
  19.                          "/remove",
  20.                          NULL};
  21.  
  22. int main(int argc, char **argv)
  23. {
  24.   int RIFS=FindRIFS();
  25.   struct REGPACK regs;
  26.   char local=0,
  27.        remote=0;
  28.   BOOL removeflag=FALSE;
  29.   int  opt;
  30.  
  31.   ArgInit(argc, argv);
  32.   if (RIFS) {
  33.     regs.r_ax=0x0000;
  34.     intr(RIFS, ®s);
  35.   }
  36.   if (!RIFS || (regs.r_ax != 0x1234))
  37.     ArgError("RCLIENT not loaded");
  38.  
  39.   while ((opt=GetOption(options)) != -1) {
  40.     switch (opt) {
  41.       case 0:
  42.         if (local)
  43.           ArgError("/local already defined");
  44.         if (strlen(GetArg()) != 1)
  45.           ArgError("syntax error");
  46.         local=*GetArg();
  47.         if (!isalpha(local))
  48.           ArgError("syntax error");
  49.         break;
  50.       case 1:
  51.         if (remote)
  52.           ArgError("/remote already defined");
  53.         if (strlen(GetArg()) != 1)
  54.           ArgError("syntax error");
  55.         remote=*GetArg();
  56.         if (!isalpha(remote))
  57.           ArgError("syntax error");
  58.         break;
  59.       case 2:
  60.         removeflag=1;
  61.         break;
  62.     }
  63.   }
  64.   if (removeflag) {
  65.     if (remote)
  66.       ArgError("syntax error");
  67.     else if (local) {
  68.       regs.r_ax=RCLIENT_UNMAP;
  69.       regs.r_bx=local;
  70.       intr(RIFS, ®s);
  71.     } else {
  72.       regs.r_ax=RCLIENT_UNMAPALL;
  73.       intr(RIFS, ®s);
  74.     }
  75.   } else if (local) {
  76.     if (!remote)
  77.       ArgError("syntax error");
  78.     else {
  79.       regs.r_ax=RCLIENT_REMAP;
  80.       regs.r_bx=(((unsigned) local) << 8) | remote;
  81.       intr(RIFS, ®s);
  82.     }
  83.   } else {
  84.     int ii;
  85.     BYTE *xlate;
  86.     regs.r_ax=RCLIENT_GETXLAT;
  87.     intr(RIFS, ®s);
  88.     xlate=MK_FP(regs.r_es, regs.r_bx);
  89.     printf("Current drive mappings:\n"
  90.            "  Local --> Remote\n");
  91.     for (ii=0; ii < 26; ii++) {
  92.       if (xlate[ii]) {
  93.         printf("   %c:        %c:\n",
  94.           'A'+ii,
  95.           xlate[ii]);
  96.       }
  97.     }
  98.   }
  99.   return 0;
  100. }
  101.